/*java jdk 1.7+
# -*- coding: utf-8 -
'''
Created on 2022年07月07日
@author: zxyong 13738196011
'''*/

package com.plugins.usereflect;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.LinkedHashMap;

import org.json.JSONObject;

import com.zxy.business.Ope_DB_Cent;
import com.zxy.business.Power_Control;
import com.zxy.business.Query_Data;
import com.zxy.cache.Cache_Power_Control;
import com.zxy.common.Com_Fun;
import com.zxy.common.Com_Para;
import com.zxy.common.Db_Common_InterFace;
import com.zxy.common.ParamName_InterFace;
import com.zxy.db1.Db_Common1;
import com.zxy.db2.Db_Common2;

//元数据表重置业务
public class A01_YY77HH_IN implements com.zxy.common.ParamName_InterFace
{
	public StringBuilder	strResult		= new StringBuilder();
	public String			user_main_id			= null;
	public String			session_id		= null;
	public String			param_name		= "";
	//t_single_table main_id
	public String			param_value1	= null;
	//web文件夹
	public String			param_value2	= null;
	public String			param_value3	= null;
	public String			param_value4	= null;
	public String			param_value5	= null;
	public String			param_value6	= null;
	public String			param_value7	= null;
	public String			param_value8	= null;
	public String			param_value9	= null;
	public String			param_value10	= null;

	@Override
	public void init_start()
	{
		try
		{
			JSONObject jso_single_table = this.get_t_single_table();
			if(jso_single_table.getJSONArray("t_single_table").length() > 0)
			{
				String temTableName = jso_single_table.getJSONArray("t_single_table").getJSONObject(0).getString("TABLE_EN_NAME");
				if(temTableName == "")
				{
					this.strResult.append(Com_Fun.get_ope_result(param_name,"0","元数据表重置业务失败，元数据表名不能为空"));
				}

				int DB_ID = Integer.valueOf(jso_single_table.getJSONArray("t_single_table").getJSONObject(0).getString("DB_ID"));
				
				//自动清除表及接口
//				StringBuilder strSql = new StringBuilder("drop table "+ temTableName);
//				Ope_DB_Cent odc = new Ope_DB_Cent();
//				Object dbcobject = odc.Get_Db_Common(DB_ID);
//				Db_Common_InterFace dbc = (Db_Common_InterFace)(odc.Obj_To_Db_Common(dbcobject));
//				dbc.CommonExec_Sql(strSql);
//
//				strSql.delete(0,strSql.length());
//				strSql = new StringBuilder("drop function funnode_"+ temTableName);
//				dbc.CommonExec_Sql(strSql);
//				
//				Db_Common1 dbc1 = new Db_Common1();
//				strSql.delete(0,strSql.length());
//				strSql.append("delete from t_proc_name where INF_EN_NAME in ('T01_sel_"
//						+ temTableName + "_ByID','T01_sel_" + temTableName
//						+ "','T01_ins_" + temTableName + "','T01_upd_"
//						+ temTableName + "','T01_del_" + temTableName + "','N01_sel_"
//						+ temTableName + "_ByID','N01_sel_" + temTableName
//						+ "','N01_ins_" + temTableName + "','N01_upd_"
//						+ temTableName + "','N01_del_" + temTableName + "','N01_sel_"
//						+ temTableName + "_ByNodeID')");
//				dbc1.CommonExec_Sql(strSql);
				
				
				// #清除缓存
				Cache_Power_Control temPcl = new Cache_Power_Control();
				temPcl.run(Com_Para.sub_code,Com_Para.sub_usercode,"T01_truncate_table","");
				Query_Data qd = new Query_Data();
				qd.Cal_Data(temPcl,Com_Para.sub_code,"T01_truncate_table",new ArrayList<String>(),"",new Hashtable<String, String>());
				// #删除元数据表及相关文件
				A01_STATICDB3_IN a01_sdb = new A01_STATICDB3_IN();
				a01_sdb.param_name = this.param_name;
				this.strResult = a01_sdb.Delete_SingleTable_Py(temTableName,this.param_value2);
				if(this.strResult.length() == 0){
					this.strResult.delete(0,strResult.length());
					this.strResult.append(Com_Fun.get_ope_result(param_name,"1","元数据表重置业务成功"));
				}
			}else
			{
				this.strResult.delete(0,strResult.length());
				this.strResult.append(Com_Fun.get_ope_result(param_name,"0","元数据表重置业务失败，元数据表记录不存在"));
			}
		}
		catch(Exception e)
		{
			this.strResult.delete(0,strResult.length());
			this.strResult.append(Com_Fun.get_ope_result(param_name,"0","元数据表重置业务失败，" + e.getMessage()));
			Com_Fun.debug_in(e,this.toString());
		}
	}

	private JSONObject get_t_single_table()
	{
		StringBuilder strSql = new StringBuilder();
		JSONObject jso = new JSONObject(new LinkedHashMap());
		try
		{
			Ope_DB_Cent odc = new Ope_DB_Cent();
			strSql.append("select MAIN_ID,TABLE_CN_NAME,TABLE_EN_NAME,DB_ID from t_single_table where main_id = '"
					+ this.param_value1 + "'");
			jso.put("t_single_table",odc.SqlToJson(1,strSql.toString()));
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString(),strSql.toString());
		}
		return jso;
	}

	/**
	 * @return strResult
	 */
	public StringBuilder getStrResult()
	{
		return strResult;
	}

	/**
	 * @param strResult
	 *            要设置的 strResult
	 */
	public void setStrResult(StringBuilder strResult)
	{
		this.strResult = strResult;
	}

	/**
	 * @return user_main_id
	 */
	public String getUser_main_id()
	{
		return user_main_id;
	}

	/**
	 * @param user_main_id
	 *            要设置的 user_main_id
	 */
	public void setUser_main_id(String user_main_id)
	{
		this.user_main_id = user_main_id;
	}

	/**
	 * @return session_id
	 */
	public String getSession_id()
	{
		return session_id;
	}

	/**
	 * @param session_id
	 *            要设置的 session_id
	 */
	public void setSession_id(String session_id)
	{
		this.session_id = session_id;
	}

	/**
	 * @return param_name
	 */
	public String getParam_name()
	{
		return param_name;
	}

	/**
	 * @param param_name
	 *            要设置的 param_name
	 */
	public void setParam_name(String param_name)
	{
		this.param_name = param_name;
	}

	/**
	 * @return param_value1
	 */
	public String getParam_value1()
	{
		return param_value1;
	}

	/**
	 * @param param_value1
	 *            要设置的 param_value1
	 */
	public void setParam_value1(String param_value1)
	{
		this.param_value1 = param_value1;
	}

	/**
	 * @return param_value2
	 */
	public String getParam_value2()
	{
		return param_value2;
	}

	/**
	 * @param param_value2
	 *            要设置的 param_value2
	 */
	public void setParam_value2(String param_value2)
	{
		this.param_value2 = param_value2;
	}

	/**
	 * @return param_value3
	 */
	public String getParam_value3()
	{
		return param_value3;
	}

	/**
	 * @param param_value3
	 *            要设置的 param_value3
	 */
	public void setParam_value3(String param_value3)
	{
		this.param_value3 = param_value3;
	}

	/**
	 * @return param_value4
	 */
	public String getParam_value4()
	{
		return param_value4;
	}

	/**
	 * @param param_value4
	 *            要设置的 param_value4
	 */
	public void setParam_value4(String param_value4)
	{
		this.param_value4 = param_value4;
	}

	/**
	 * @return param_value5
	 */
	public String getParam_value5()
	{
		return param_value5;
	}

	/**
	 * @param param_value5
	 *            要设置的 param_value5
	 */
	public void setParam_value5(String param_value5)
	{
		this.param_value5 = param_value5;
	}

	/**
	 * @return param_value6
	 */
	public String getParam_value6()
	{
		return param_value6;
	}

	/**
	 * @param param_value6
	 *            要设置的 param_value6
	 */
	public void setParam_value6(String param_value6)
	{
		this.param_value6 = param_value6;
	}

	/**
	 * @return param_value7
	 */
	public String getParam_value7()
	{
		return param_value7;
	}

	/**
	 * @param param_value7
	 *            要设置的 param_value7
	 */
	public void setParam_value7(String param_value7)
	{
		this.param_value7 = param_value7;
	}

	/**
	 * @return param_value8
	 */
	public String getParam_value8()
	{
		return param_value8;
	}

	/**
	 * @param param_value8
	 *            要设置的 param_value8
	 */
	public void setParam_value8(String param_value8)
	{
		this.param_value8 = param_value8;
	}

	/**
	 * @return param_value9
	 */
	public String getParam_value9()
	{
		return param_value9;
	}

	/**
	 * @param param_value9
	 *            要设置的 param_value9
	 */
	public void setParam_value9(String param_value9)
	{
		this.param_value9 = param_value9;
	}

	/**
	 * @return param_value10
	 */
	public String getParam_value10()
	{
		return param_value10;
	}

	/**
	 * @param param_value10
	 *            要设置的 param_value10
	 */
	public void setParam_value10(String param_value10)
	{
		this.param_value10 = param_value10;
	}
}